package com.codedancer.campus.client.api.updateLog;

import com.codedancer.campus.client.service.IUpdateLogService;
import com.codedancer.campus.client.service.vo.updateLog.UpdateLogVo;
import com.codedancer.campus.common.core.BaseApi;
import com.codedancer.campus.common.response.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/update-log")
@CrossOrigin(methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.DELETE,
    RequestMethod.PUT}, maxAge = 3600)
@Api(value = "更新日志Api", description = "更新日志Api", tags = "更新日志Api")
public class UpdateLogApi extends BaseApi {

    @Autowired
    private IUpdateLogService updateLogService;

    @GetMapping("/latest")
    @ApiOperation("获取最新的更新日志")
    public ApiResponse<UpdateLogVo> latest() {
        return success(updateLogService.latest(currentLoginUuid()));
    }

    @PutMapping("/read/{uuid}")
    @ApiOperation("已读最新更新日志")
    public ApiResponse<Void> read(
        @PathVariable(value = "uuid", required = true) @ApiParam(value = "更新日志uuid", required = true) String uuid) {
        updateLogService.read(currentLoginUuid(),uuid);
        return success();
    }
}
